package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            MyApplicationTheme {
                Scaffold(
                    modifier = Modifier.fillMaxSize(),
                    containerColor = Color(0xFFF0FFF3) // 浅绿色背景 (AliceBlue)
                ) { innerPadding ->
                    Greeting(
                        name = "计算机2301洪瑞",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    LocalContext.current
    val img: Painter = painterResource(id = R.drawable.hongrui)
    val phoneIconPainter: Painter = painterResource(id = R.drawable.dskdksk)

    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.fillMaxSize()
    ) {
        Spacer(modifier = Modifier.height(50.dp))

        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.fillMaxWidth().weight(1f, false)
        ) {
            Image(
                painter = img,
                contentDescription = "R.drawable.hongrui",
                modifier = Modifier
                    .size(120.dp)
                    .padding(vertical = 10.dp),
            )
            Text(
                text = "Hello $name!",
                textAlign = TextAlign.Center,
                fontSize = 50.sp,
                lineHeight = 50.sp,
                modifier = Modifier.padding(vertical = 10.dp)
            )
            Text(
                text = "个人信息介绍",
                fontSize = 30.sp,
                lineHeight = 30.sp,
                modifier = Modifier.padding(vertical = 5.dp)
            )
        }

        Spacer(modifier = Modifier.height(30.dp))

        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = modifier.fillMaxWidth().weight(1f, false)
        ) {
            Row(
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)
            ) {
                Image(
                    painter = phoneIconPainter,
                    contentDescription = "Phone Icon 1",
                    modifier = Modifier
                        .size(40.dp)
                )
                Text(
                    text = "+666666666",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier.padding(horizontal = 8.dp)
                )
            }
            Row(
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)
            ) {
                Image(
                    painter = phoneIconPainter,
                    contentDescription = "Phone Icon 2",
                    modifier = Modifier
                        .size(40.dp)
                )
                Text(
                    text = "+777777777",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier.padding(horizontal = 8.dp)
                )
            }
            Row(
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)
            ) {
                Image(
                    painter = phoneIconPainter,
                    contentDescription = "Phone Icon 3",
                    modifier = Modifier
                        .size(40.dp),
                )
                Text(
                    text = "+888888888",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier.padding(horizontal = 8.dp)
                )
            }
        }
        Spacer(modifier = Modifier.height(50.dp))
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    MyApplicationTheme {
        Scaffold(
            containerColor = Color(0xFFF0FFF3) // 浅绿色背景
        ) { paddingValues ->
            Greeting(name = "Preview User", modifier = Modifier.padding(paddingValues))
        }
    }
}